package cn.autumnorange.app.money.api;

import cn.autumnorange.app.common.dto.ResultDto;
import cn.autumnorange.app.money.api.dto.MoneyDto;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class AccountFallbackFactory2 implements FallbackFactory<MoneyService2> {

  @Override
  public MoneyService2 create(Throwable throwable) {
    return new MoneyService2() {
      @Override
      public ResponseEntity<ResultDto<MoneyDto>> add2(Long version, Long money) {
        log.info("account-service add2 error massgae:" + throwable.getMessage());
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR.value())
            .body(
                ResultDto.createResult(
                    HttpStatus.INTERNAL_SERVER_ERROR.value(),
                    null,
                    throwable.getMessage(),
                    null,
                    null,
                    null));
      }

      @Override
      public ResponseEntity<ResultDto<Long>> getVersion(Long id) {
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR.value())
            .body(
                ResultDto.createResult(
                    HttpStatus.INTERNAL_SERVER_ERROR.value(),
                    null,
                    throwable.getMessage(),
                    null,
                    null,
                    null));
      }
    };
  }
}
